package cn.wolfcode.qo;

import lombok.Getter;
import lombok.ToString;

import java.util.List;

// 封装分页查询数据
@Getter
@ToString
public class PageResult<T> {
    // 当前页
    private int currentPage;
    // 每页条数
    private int pageSize;

    // 总数量
    private int totalCount;
    // 数据
    private List<T> data;

    // 总页数
    private int totalPage;
    // 上一页
    private int prevPage;
    // 下一页
    private int nextPage;

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize
                : this.totalCount / this.pageSize + 1;
        this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
        this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 : this.totalPage;
    }
}
